﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class bl_Site : System.Web.UI.MasterPage
{
    public string Root { get; set; }


    protected void Page_Init(object sender, EventArgs e)
    {
        Root = "http://" + Request.Url.Host + Request.ApplicationPath;
        Root += Root.EndsWith("/") ? "" : "/";
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        feedNews.DataSource = new DataBase.NewsFeedData().LoadNews(DateTime.MinValue, 6);
        feedNews.DataBind();
    }
    DateTime calcdate = new DateTime(1970, 1, 1, 3, 0, 00);
    protected void feedNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        var item = (DataBase.NewsFeedData)e.Item.DataItem;
        if (item != null)
        {
            var li = (Literal)e.Item.FindControl("NewsLit");
            var ms = (item.CreateDate - calcdate).TotalMilliseconds;
            if (item.Type == DataBase.NewsFeedData.NewsType.COMMENT)
            {
                li.Text = "<li><a href=\"javascript:void\">" + item.Author + "</a> - მ დატოვა კომენტარი: " +
                    "<b>" + item.Text + " </b>სტატიაზე: " +
                    "<a href=\"" + Root + "article.aspx?title=" + item.Title + "&id=" + item.ArticleID + "\">" + item.Title + "</a>" +
                    "<b> <a href=\"" + Root + "article.aspx?title=" + item.Title + "&id=" + item.ArticleID + "#comment-" + item.CommentID + "\">ნახე კომენტარი » </a></b>" +
                    "<small><p style=\"display: none\">" + ms + "</p>" + item.CreateDate + "</small>" +
                "</li>";
            }
            else if (item.Type == DataBase.NewsFeedData.NewsType.ARTICLE)
            {
                li.Text = "<li><a href=\"javascript:void\">" + item.Author + "</a> - მ დაამატა სტატია <a href=\"javascript:void\">" +
                            item.Title + "</a><small><p style=\"display: none\">" + ms + "</p>" + item.CreateDate + "</small> </li>";
            }
        }
    }
}